package udp;

import java.io.IOException;
import java.net.*;
import java.nio.charset.StandardCharsets;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Client
 * Package: udp
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-14
 * Time: 17:04
 */

public class Client {
    public static void main(String[] args) throws IOException {

        //1.UDP 是创建DatagramSocket
        DatagramSocket datagramSocket = new DatagramSocket();

        InetAddress byName = InetAddress.getByName("127.0.0.1");
        byte[] bytes = "hello".getBytes("utf-8");
        //发送数据的方式是数据表 将要发送的数据和 服务器端口 和 IP封装到数据报中
        DatagramPacket packet = new DatagramPacket(bytes, 0, bytes.length, byName, 9999);
        //发送数据
        datagramSocket.send(packet);

        //关闭资源
        datagramSocket.close();

    }
}
